<!-- 公司sop配置 -->
<template>
  <div>
    <dt-modal-edit
      ref="info"
      :title="title"
      :label-width="100"
      okText="确定"
      :width="1100"
      @ok="onOk"
      :loading="btnLoading">
      <span class="tips">
        <Icon type="md-alert" class="tips_icon" />
        提示：{{ info.tips }}
      </span>
      <div class="conpany_sop_edit">
        <Row type="flex" justify="start" class="sop_content">
          <!-- <Col span="8" v-for="(item, index) in info.SopSort" :key="index"> -->
          <Col span="8">
            <Row type="flex" justify="start" class="item_class">
              <Col span="10">
                {{ SopSort.sopName }}
              </Col>
              <Col span="14">
                <!-- <i-switch
                  size="large"
                  @on-change="changeTaskSwitch(item)"
                  v-model="item.isTaskAssess"
                  v-if="item.isTaskShowBtn">
                  <span slot="open">{{ item.openTaskTxt }}2</span>
                  <span slot="close">{{ item.closeTaskTxt }}</span>
                </i-switch> -->
                <i-switch
                  size="large"
                  v-model="SopSort.isAssess"
                  @on-change="sChange">
                  <span slot="open">{{ SopSort.openTxt }}</span>
                  <span slot="close">{{ SopSort.closeTxt }}</span>
                </i-switch>
              </Col>
            </Row>
          </Col>
        </Row>
      </div>
      <div class="sync">
        <Row>
          <Col flex="100px">
            <p class="sync_txt">同步至：</p>
          </Col>
          <Col flex="auto">
            <RadioGroup v-model="isSynchronize" type="button">
              <Radio :label="1">全部案场</Radio>
              <Radio :label="0">标准案场（“自定义规则案场”不会同步）</Radio>
            </RadioGroup>
          </Col>
        </Row>
        <div class="sync_tips" v-show="info.type == '1' || info.type == '3'">
          注意：两种同步方式均不会对，“已撤场”、“已结案”状态的案场进行同步；
        </div>
      </div>
    </dt-modal-edit>
  </div>
</template>

<script>
  import sopApi from '@/biz/buildingManagement/sopConfig'
  export default {
    data() {
      return {
        title: '',
        info: {},
        isSynchronize: 0,
        btnLoading: false,
        SopSort: {}
      }
    },
    methods: {
      sChange(val) {},
      changeTaskSwitch(data) {
        if (!data.isTaskAssess) {
          data.isAssess = false
        }
      },
      show(data) {
        this.title = data.label
        this.isSynchronize = 0
        this.info = this.$tool.deepClone(data)
        console.log(this.info, 'info')
        this.SopSort = this.info.SopSort[0]
        this.$refs.info.show()
      },
      onOk() {
        this.btnLoading = true
        let sopPlatformAuditSwitchReqs = []
        this.info.SopSort.forEach((item) => {
          let obj = {
            sopType: item.sopType,
            isAssess: item.isAssess ? 1 : 0
          }
          if (item.type == 1) {
            obj.isTaskAssess = item.isTaskAssess ? 1 : 0
          }
          sopPlatformAuditSwitchReqs.push(obj)
        })
        let params = {
          configId: this.SopSort.id,
          isAssess: this.SopSort.isAssess,
          // isTaskAssess: true,
          updateAll: this.isSynchronize == 1 ? true : false
        }
        sopApi
          .auditPlatformSwitch1(params)
          .then((res) => {
            this.btnLoading = false
            this.$refs.info.hide()
            this.$Message.success('修改成功！')
            this.$emit('success')
          })
          .catch(() => {
            this.btnLoading = false
          })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .tips {
    text-align: right;
    line-height: 32px;
    font-size: 14px;

    .tips_icon {
      font-size: 20px;
      color: #0f42a7;
      vertical-align: sub;
    }
  }

  .conpany_sop_edit {
    .ivu-switch-large {
      width: 80px;
      height: 30px;
      line-height: 30px;
      margin-right: 5px;
    }

    ::v-deep.ivu-switch .ivu-switch-inner {
      left: 30px;
    }

    ::v-deep.ivu-switch-checked .ivu-switch-inner {
      left: 7px;
    }

    .ivu-switch-large.ivu-switch-checked:after {
      left: 50px;
      height: 26px;
      width: 26px;
    }

    .ivu-switch:after {
      height: 26px;
      width: 26px;
    }

    .sop_content {
      margin-bottom: 30px;

      .item_class {
        padding: 15px 0;
        font-size: 16px;
        line-height: 30px;
      }
    }
  }

  .sync {
    padding-top: 20px;
    border-top: 1px solid #e8e8e8;

    .sync_txt {
      line-height: 32px;
      font-size: 16px;
    }

    .sync_tips {
      font-size: 12px;
      color: #999;
      margin-top: 10px;
    }
  }
</style>
